<?php
// 新增商铺信息
require $this->website['path']['action'] . '/admin/isedit.php';

$json = array('status' => 'error', 'msg' => '', 'data' => []);

$data = fn_post('data');

$data = json_decode($data, 1);
//data['shops']
//data['postage']
//data['check']

if (!count($data['shops'])) {
	$json['msg'] = '请添加基本信息 ';
} elseif ($this->website['class']['db']
		->table('shops')
		->where('id=?', $data['shops']['id'])
		->count()) {
	$json['msg'] = '该用户已绑定，一个用户只能绑定一个商铺 ';
} else {
	// shops
	$field = array_keys($data['shops']);
	$value = array_values($data['shops']);
	$field[] = 'createtime';
	$value[] = $_SERVER['REQUEST_TIME'];

	// $json['data']['field'] = $field;
	// $json['data']['value'] = $value;
	// $this->json_encode($json);

	$this->website['class']['db']
		->table('shops')
		->field($field)
		->value($value)
		->insert();
	$count = $this->website['class']['db']
		->table('shops')
		->where('id=?', $data['shops']['id'])
		->limit(1)
		->count();

	if (!$count) {
		$json['msg'] = '保存商铺数据错误';
		$json['data'] = $this->website['class']['db']->sql;
		$this->json_encode($json);
	}
 
	$json['status'] = 'ok';
	$json['msg'] = '新增商铺成功';
}
// $json['data'] = $this->website['class']['db']->sql;
$this->json_encode($json);
